﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace CircuitBreaker
{
    public class OpenState : CircuitBreakerState
    {
        private readonly Timer timer;

        public OpenState(CircuitBreaker circuitBreaker)
            : base(circuitBreaker)
        {
            timer = new Timer(new TimerCallback(state => circuitBreaker.HalfOpen()), null, circuitBreaker.PeriodToHalfOpen, Timeout.Infinite);
        }

        public override void ProtectedCodeIsAboutToBeCalled()
        {
            base.ProtectedCodeIsAboutToBeCalled();
            throw new OpenCircuitException();
        }
    }

}
